package com.oms.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liudecai.utils.common.CommonUtils;
import com.oms.bean.RequestBean;

@WebServlet("/TestRequest")
public class TestRequest extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public TestRequest() {
        super();
    }
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
		Object name = request.getParameter("username");
		System.out.println(name);
		response.getWriter().append("Served at: ").append(request.getContextPath());
		//调用方法完成对表单数据封装到Bean中
		RequestBean bean = (RequestBean)CommonUtils.MyReq2Bean(request, new RequestBean());
//		RequestBean bean = (RequestBean)CommonUtils.parseRequest(request, RequestBean.class);
		System.out.println(bean);
	    response.getWriter().write("name="+bean.getUsername()+"pass="+bean.getPassword()+"phone="+bean.getTelephone());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
